
from pyvision.core.Enums import ComponentModelTagEnum
from typing import List
from .Jsonable import Jsonable


class Props(Jsonable):
    pass


class ComponentModel(Jsonable):

    def __init__(self, id: str, tag: ComponentModelTagEnum = ComponentModelTagEnum.NoSet) -> None:
        super().__init__()
        self.id = id
        self.tag = tag
        self.props: Props = Props()

    def set_tag(self, tag: ComponentModelTagEnum):
        self.tag = tag
        return self

    def set_props(self, props: Props):
        self.props = props
        return self

    def _2json(self):
        return {
            'ID': self.id,
            'Tag': self.tag.value,
            'Props': self.props
        }


class RowContainer(Jsonable):
    def __init__(self) -> None:
        self.components: List[ComponentModel] = []
        self.styles = {
            'justify': 'center',
            'align': 'center'
        }

    def add_component(self, cp: ComponentModel):
        self.components.append(cp)
        return self

    def add_components(self, *cps: ComponentModel):
        self.components.extend(cps)
        return self

    def set_styles(self, **kws):
        self.styles.update(**kws)
        return self

    def _2json(self):
        return {
            'Styles': self.styles,
            'Components': self.components
        }


class Layout(Jsonable):

    def __init__(self) -> None:
        super().__init__()
        self.rows: List[RowContainer] = []

    def add_row(self, row: RowContainer):
        self.rows.append(row)
        return self

    def _2json(self):
        return {
            'Rows': self.rows
        }
